<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="../../component/pear/css/pear.css" />
    <style>
        h1 {
            margin-top: 200px;
            color: #5FB878;
        }

        .layui-card-body {
            text-align: center;
            height: 500px;
        }
    </style>
</head>

<body class="pear-container">
    <div class="layui-card">
        <div class="layui-card-header"></div>
        <div class="layui-card-body">
            <form class="layui-form" action="" onsubmit="return false">
                <div class="layui-form-item">
                    <label class="layui-form-label">发送对象</label>
                    <div class="layui-input-block">
                        <input type="hidden" name="users" id="users">
                        <input type="text" name="usersText" id="usersText" required lay-verify="required"
                            placeholder="请选择发送对象" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">发送内容</label>
                    <div class="layui-input-block">
                        <textarea name="content" placeholder="请输入发送内容" required lay-verify="required"
                            class="layui-textarea"></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="sendMsg">发送</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</body>
<script src="../../component/layui/layui.js"></script>
<script src="../../component/pear/pear.js"></script>
<script>
    layui.use(['table', 'form', 'jquery'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;

        $("#usersText").click(function () {
            layer.open({
                title: "分配用户",
                content: "../user/yhlb.html",
                type: 2,
                area: ["1620px", "780px"],
                offset: 'auto',
                btn: ["确定", "取消"]
                , yes: function (index, layero) {
                    var body = layer.getChildFrame('body', index);
                    var iframeWin = window[layero.find('iframe')[0]['name']];
                    var checkStatus = iframeWin.layui.table.checkStatus('user-table');
                    let ids = "";
                    let names = "";
                    if (checkStatus.data.length > 0) {
                        for (let i = 0; i < checkStatus.data.length; i++) {
                            ids += checkStatus.data[i].uid + ";";
                            names += checkStatus.data[i].nickname + ";";
                        }
                        $("#users").val(ids);
                        $("#usersText").val(names);
                        layer.close(index)
                        return false
                    }


                }
                , cancel: function () {
                    //右上角关闭回调

                    //return false 开启该代码可禁止点击该按钮关闭
                }
            })

        });

        form.on('submit(sendMsg)', function (data) {
            $.ajax({
                url: '/api/messages/qfxx',
                data: JSON.stringify(data.field),
                contentType: 'application/json',
                dataType: 'json',
                type: 'post',
                success: function (result) {
                    if (result.code == 0) {
                        layer.msg(result.msg, { icon: 1, time: 1000 });
                    } else {
                        layer.msg(result.msg, { icon: 2, time: 1000 });
                    }
                }
            })
            return false;
        });

    });

</script>

</html>